package com.ky.leetcode.剑指Offer;

/*

统计一个数字在排序数组中出现的次数。

    示例 1:
    输入: nums = [5,7,7,8,8,10], target = 8
    输出: 2
    示例 2:

    输入: nums = [5,7,7,8,8,10], target = 6
    输出: 0


    提示：
    0 <= nums.length <= 105
    -109 <= nums[i] <= 109
    nums 是一个非递减数组
    -109 <= target <= 109

*/

public class 剑指Offer53I在排序数组中查找数字I {

    public static void main(String[] args) {
        int[] nums = new int[]{5, 7, 7, 8, 8, 10};
        System.out.println(new Solution().search(nums, 6));
    }

    static class Solution {
        public int search(int[] nums, int target) {
            int count = 0;
            for (int i = 0; i < nums.length; i++) {
                if (nums[i] == target) {
                    count++;
                }
            }
            return count;
        }
    }
}
